package cloud.xlh.dynamic_env_refresh_server.utils;

import cloud.xlh.infrastructure.utils.FileUtil;
import cloud.xlh.infrastructure.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/3/16 11:46
 * @ Description:
 */
@Slf4j
public class MD5Util {
    public static List<String> compareMd5(HttpServletRequest req, HttpServletResponse rsp, Map<String, String> clientMd5Map) {
            /*String config2JsonString = FileUtil.readCommonFileAndToStr(FileUtil.PathTypeCode.ABSOLUTE_PATH.getCode(), "D:\\development\\environment\\idea\\IdeaProjects\\xlh_osms\\module\\dynamic-env-refresh-server\\src\\main\\resources\\serviceCallList.json");
            String valueFromRemote = JSONObjectUtil.getAnyNodeDataFromJsonStr(config2JsonString, "svcCode");
            */
        //远程本地配置
        Properties remoteProperties = FileUtil.readApplicationYMLFileAndTurnToProperties("D:\\development\\environment\\idea\\IdeaProjects\\xlh_osms\\module\\dynamic-env-refresh-server\\src\\main\\resources\\application.yml", FileUtil.PathTypeCode.ABSOLUTE_PATH.getCode());
        String remoteServiceCallListFileLocation = remoteProperties.getProperty("remote.serviceCallListFile.location");
        Map map = FileUtil.readFromJsonFile(remoteServiceCallListFileLocation, null);
        String valueFromRemote = (String) map.get("svcCode");
        log.info("远程本地配置->{}" , valueFromRemote);
        //客户端本地配置
        String valueFormLocal = clientMd5Map.get("svcCode");
        log.info("客户端本地配置->{}" , valueFormLocal);
        List<String> changeKeyList = new ArrayList<>();
        if (!StringUtil.isEmpty(valueFromRemote) && !valueFromRemote.equals(valueFormLocal)) {
            changeKeyList.add("svcCode");
            return changeKeyList;
        }
        return null;
    }
}
